package cn.yqx.bankshop.user.service.impl;

import cn.yqx.bankshop.user.dao.BuSupplierMapper;
import cn.yqx.bankshop.user.dao.SysUserAccountMapper;
import cn.yqx.bankshop.user.pojo.BuSupplier;
import cn.yqx.bankshop.user.pojo.BuSupplierExample;
import cn.yqx.bankshop.user.pojo.SysUserAccount;
import cn.yqx.bankshop.user.pojo.SysUserAccountExample;
import cn.yqx.bankshop.user.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    BuSupplierMapper mapper ;
    @Autowired
    SysUserAccountMapper sysUserAccountMapper ;
    @Override
    public BuSupplier findSupplierById(Long supplierId) {
        BuSupplierExample example = new BuSupplierExample() ;
        example.or().andSupplierIdEqualTo(supplierId) ;
        List<BuSupplier> list = mapper.selectByExample(example) ;

        if(list.isEmpty()){
            return  null ;
        }

        SysUserAccountExample sysUserAccountExample = new SysUserAccountExample() ;
        sysUserAccountExample.or().andUserIdEqualTo(supplierId) ;
        SysUserAccount sysUserAccount = sysUserAccountMapper.selectByExample(sysUserAccountExample).get(0) ;
        BuSupplier buSupplier = list.get(0);
        buSupplier.setMobilePhone(sysUserAccount.getMobileTel());
        return  buSupplier;
    }

    @Override
    public List<BuSupplier> findSuppliersByIds(List<Long> ids) {
        BuSupplierExample example = new BuSupplierExample() ;
        example.or().andSupplierIdIn(ids) ;
        return mapper.selectByExample(example) ;
    }
}
